package com.yidu.ladder.delivery.controller;

import java.util.List;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.ladder.base.domain.Area;
import com.yidu.ladder.delivery.domain.CalculateFeeVo;
import com.yidu.ladder.delivery.service.FreeService;

/**
 * 运费网络控制器
 * 
 * @author yy
 * @since 2019-12-20
 *
 */
@Controller
@RequestMapping("/system")
public class FreeController {

	/**
	 * 关联运费业务逻辑层
	 */
	@Autowired
	private FreeService freeService;

	public FreeService getFreeService() {
		return freeService;
	}

	public void setFreeService(FreeService freeService) {
		this.freeService = freeService;
	}

	/**
	 * 管理页面
	 * 
	 * @return 运费管理页的URL
	 */
	@RequestMapping(value = "free")
	public String free() {
		return "sys/free";
	}

	/**
	 * 查询所有的省
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "findAllProvince")
	public List<Area> findAllProvince() {
		// 执行查询所有的省方法
		List<Area> result = freeService.queryAllProvince();
		// 返回结果
		return result;
	}

	/**
	 * 查询某个省下所有市
	 * 
	 * @param province 省份
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "findAllCity")
	public List<Area> findAllCity(String province) {
		// 执行查询某个省下所有市方法
		List<Area> result = freeService.queryAllCity(province);
		// 返回结果
		return result;
	}

	/**
	 * 查询某个市下所有县
	 * 
	 * @param city 城市
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "findAllDistrict")
	public List<Area> findAllDistrict(String city) {
		// 执行查询某个市下所有县方法
		List<Area> result = freeService.queryAllDistrict(city);
		// 返回结果
		return result;
	}

	/**
	 * 计算运费
	 * 
	 * @param feeVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "calFee")
	public Map<String, Object> calFee(CalculateFeeVo feeVo) {
		return freeService.calculateTheShipmentFree(feeVo);
	}
}
